<template>
    <div id="Home">
        <el-container class="ZCon">
            <el-header>
                <div class="headLogo">
                    <img src="../assets/images/tan.png" alt="">
                </div>

                <span class="headTitle">默鱼</span>
                <span class="headQuit" @click="edit">退出</span>
            </el-header>
            <el-container>

                <el-aside :width="onoff?'60px':'200px'">
                    <div class="shrink" @click="shrink">
                        <i :class="onoff ? 'el-icon-arrow-right':'el-icon-arrow-left'"></i>
                    </div>
                    <el-menu background-color="#545c64"
                            text-color="#fff"
                            active-text-color="rgb(64,158,255)"
                             :unique-opened="true"
                            :collapse="onoff"
                             :collapse-transition="false"
                            :router="true"
                             :default-active="navStorage">
                        <el-submenu :index="item.id" v-for="(item,index) in navList" :key="index">
                            <template slot="title">
                                <i :class="navIcon[item.id]"></i>
                                <span>{{item.authName}}</span>
                            </template>

                            <el-menu-item @click="changeNavStorage(item1.path)" :index="item1.path" v-for="(item1,index1) in item.childer" :key="index1">
                                <template slot="title">
                                    <i class="el-icon-menu"></i>
                                    <span>{{item1.authName}}</span>
                                </template>
                            </el-menu-item>
                        </el-submenu>

                    </el-menu>
                </el-aside>

                <el-main>
                    <router-view></router-view>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>

<script>
    export default {
        name: "Home",
        data(){
            return {
                navList:[],
                navIcon:{
                    "1":"el-icon-user-solid",
                    "2":"el-icon-s-platform"
                },
                onoff:false,
                navStorage:""
            }
        },
        created(){
            this.getNavList();
            this.navStorage = window.sessionStorage.getItem("navStorage");
        },
        methods:{
            changeNavStorage: function (n) {
                window.sessionStorage.setItem("navStorage", n);
                this.navStorage = n;

            },
            edit(){
                var onoff = confirm("你确定退出么？");
                if(onoff){
                    window.sessionStorage.clear();
                    this.$router.push("/");
                }else{
                    return false;
                }
            },
            async getNavList(){

                var {data:res} = await this.$http.get("./navList.json");

                this.navList = res.data;
            },
            shrink(){
                this.onoff = !this.onoff
            }
        }
    }
</script>

<style scoped lang="less">
    #Home,.ZCon{
        height: 100%;
    }
    .el-header{
        background-color: rgb(60, 65, 71);

        .headLogo{
            display: inline-block;
            width: 48px;
            height: 48px;
            margin-top: 5px;
            border-radius: 50%;
            overflow: hidden;

            img{
                width: 100%;
            }

        }
        .headTitle{
            display: inline-block;
            margin-left: 20px;
            margin-top: 10px;
            font-size: 30px;
            color: #fff;
            vertical-align: top;
        }
        .headQuit{
            float: right;
            margin-right: 60px;
            margin-top: 18px;
            color: #fff;
            cursor: pointer;
        }
        .headQuit:hover{
            color:red;
        }
    }
    .el-aside{
        background-color: rgb(84,92,100);

        .el-menu{
            border-right: 0;
        }
        .shrink{
            text-align: center;
            font-size: 20px;
            color: #636363;
            background-color: #3d3d3d;
            i{
                cursor:pointer;
            }

        }
    }
    .el-main{
        background-color: #eee;

    }
</style>
